#include <iostream>
#include <unistd.h>
#include <signal.h>

using namespace std;

void PrintPending(sigset_t &pending)
{
    for (int signo = 31; signo > 0; signo--)
    {
        if (sigismember(&pending, signo))
            cout << "1";
        else
            cout << "0";
    }
    cout << endl;
}

void handler(int sig)
{
    cout << "get a sig : " << sig << endl;
    while(1)
    {
        sigset_t pending;
        int m = sigpending(&pending);
        PrintPending(pending);
        sleep(1);
    }
}

int main()
{
    struct sigaction act, oact;
    act.sa_handler = handler;
    sigemptyset(&act.sa_mask);
    //sigaddset(&act.sa_mask, 4); // 阻塞4信号
    act.sa_flags = 0;

    sigaction(SIGINT, &act, &oact); // 会在处理该信号时堵塞该信号:同一时间只会处理一个该信号

    while(1)
    {
        cout << "hello mypid: " << getpid() << endl;
        sleep(1);
    }

    return 0;
}
